<html>
<head><meta charset="utf-8"><title>SNAFU-specific lints · clippy · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/index.html">clippy</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/SNAFU-specific.20lints.html">SNAFU-specific lints</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="246266916"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/SNAFU-specific%20lints/near/246266916" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/SNAFU-specific.20lints.html#246266916">(Jul 16 2021 at 19:18)</a>:</h4>
<p>I chimed in on <a href="https://github.com/rust-lang/rust-clippy/issues/6872">Feature request: custom library-specific lints</a> too, but assuming that the answer was just "yeah, put it in Clippy"...</p>
<p>SNAFU takes an enum like this:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">enum</span> <span class="nc">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">Bar</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">name</span>: <span class="nb">String</span> <span class="p">},</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>and generates the struct (along with some trait implementations)</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">BarSnafu</span><span class="o">&lt;</span><span class="n">T</span>: <span class="nb">Into</span><span class="o">&lt;</span><span class="nb">String</span><span class="o">&gt;&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">name</span>: <span class="nc">T</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>I'd like to lint that usages of <code>BarSnafu</code> should not allocate in the struct literal (the <code>into</code> bound is called conditionally, so allocating always is wasteful). </p>
<p>How could I go about poking at Clippy to add such a lint?</p>



<a name="246275443"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/SNAFU-specific%20lints/near/246275443" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/SNAFU-specific.20lints.html#246275443">(Jul 16 2021 at 20:38)</a>:</h4>
<p>cc <a href="https://internals.rust-lang.org/t/proposal-stabilizable-proc-macro-based-lints/15022/">https://internals.rust-lang.org/t/proposal-stabilizable-proc-macro-based-lints/15022/</a></p>



<a name="246278363"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/SNAFU-specific%20lints/near/246278363" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/SNAFU-specific.20lints.html#246278363">(Jul 16 2021 at 21:01)</a>:</h4>
<p>That's not particularly relevant to the question of how I would implement this specific lint in Clippy though.</p>



<a name="246309936"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/SNAFU-specific%20lints/near/246309936" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/SNAFU-specific.20lints.html#246309936">(Jul 17 2021 at 07:07)</a>:</h4>
<p>You have to find an argument for the lint, so that it is generally applicable and not just for one crate. There is the <a href="https://github.com/trailofbits/dylint">dylint</a> project, if you want to implement crate specific lints.</p>



<a name="246328957"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/SNAFU-specific%20lints/near/246328957" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/SNAFU-specific.20lints.html#246328957">(Jul 17 2021 at 15:03)</a>:</h4>
<p><span class="user-mention" data-user-id="264664">@flip1995</span> you might want to ensure all project contributors agree on that and have a unified message:</p>
<blockquote>
<p>In general we have no qualms about crate specific lints (see e.g. the regex lints).</p>
</blockquote>
<p><a href="https://github.com/rust-lang/rust-clippy/issues/6872#issuecomment-793442677">https://github.com/rust-lang/rust-clippy/issues/6872#issuecomment-793442677</a></p>



<a name="246329419"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/SNAFU-specific%20lints/near/246329419" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/SNAFU-specific.20lints.html#246329419">(Jul 17 2021 at 15:15)</a>:</h4>
<p><a href="https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md#what-lints-belong-in-clippy">https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md#what-lints-belong-in-clippy</a></p>
<p>This was already defined. The TL;DR and relevant part for this discussion are these points:</p>
<blockquote>
<p>Main category lints need to be something the community has general agreement on</p>
</blockquote>
<blockquote>
<p>Generally, if a lint is triggered, this should be useful to most Rust programmers</p>
</blockquote>
<blockquote>
<p>Lints which are "pedantic" should still roughly fall into one of the main categories</p>
</blockquote>
<blockquote>
<p>Similar rules for "nursery" except their reason for being allow by default is lack of maturity</p>
</blockquote>
<blockquote>
<p>"restriction" lints follow all the rules for semantic changes, but do not bother with the rules for the lint being useful to most rust programmers</p>
</blockquote>
<p>So you could argue that crate specific lints could go in <code>restriction</code>, but until now we interpreted that restriction group definition as "Rust code that is generally ok, but may be problematic in some specific crates". Not as "only problematic in <strong>one</strong> crate".</p>



<a name="246343237"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/SNAFU-specific%20lints/near/246343237" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/SNAFU-specific.20lints.html#246343237">(Jul 17 2021 at 20:48)</a>:</h4>
<p><span class="user-mention" data-user-id="264664">@flip1995</span> I’m not saying what path clippy should choose. I’m saying that one of your team members is encouraging crate-specific lints, stating that clippy would accept them. It’s not a good idea to have one member saying something that the rest of the team disagrees with.</p>



<a name="246343379"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/SNAFU-specific%20lints/near/246343379" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/SNAFU-specific.20lints.html#246343379">(Jul 17 2021 at 20:52)</a>:</h4>
<blockquote>
<p>only problematic in <strong>one</strong> crate</p>
</blockquote>
<p>To be clear, I’m looking for a way to provide lints for all users of SNAFU. Depending on how you want to interpret that, it’s not a problem “in one crate”. </p>
<p>Another way of saying it is that I’d like to provide lints for the <em>public api</em> of my crate, which by definition affects more than one crate.</p>



<a name="246348302"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/SNAFU-specific%20lints/near/246348302" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/SNAFU-specific.20lints.html#246348302">(Jul 17 2021 at 22:50)</a>:</h4>
<p>Having not read most of this conversation, I don't think clippy should be accepting crate-specific lints. Given that any change in the compiler internals could require changes to a lint, permitting crate-specific lints could plausibly lead to clippy as a whole becoming unmaintainable in the long-term.</p>



<a name="246350290"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/SNAFU-specific%20lints/near/246350290" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cameron Steffen <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/SNAFU-specific.20lints.html#246350290">(Jul 17 2021 at 23:49)</a>:</h4>
<p>It's a tough situation because there is no good, or at least standardized, solution for crate-specific lints. I agree its not tenable for Clippy to accepts lints for any crate. My perception is that Clippy has a few crate-specific lints only for crates that are ubiquitous, like regex.</p>



<a name="246350400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/SNAFU-specific%20lints/near/246350400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/SNAFU-specific.20lints.html#246350400">(Jul 17 2021 at 23:52)</a>:</h4>
<p>That's where I'm looking into what it would take to create crate-specific lints. That's an aside from this topic though.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>